<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>adwebmob</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<?php
ob_start();
session_start();
//include 'top3.php';
//include("utils.php");

include("UserIncludes/DbConfig.php");

//main_content("mainBuySpace();");

if(!isset($_SESSION[siteuserId]) || $_SESSION[siteuserId]=='')
	echo '<script>window.location="index.php"</script>';


// Start Coming from popup
if(isset($_GET['form_id']) && $_GET['form_id'] != '')
{
$_SESSION['form_id'] = $_GET['form_id'];
}
// end coming from pop


if($_SESSION['langId']!="")
	{
		$langId=$_SESSION['langId'];
	}
	else
	{
		$langId="1";
	}


 if(isset($_POST['hidden_field'.$_SESSION['form_id']]) && $_POST['hidden_field'.$_SESSION['form_id']] == 'www')
 {
$garbage = 'garbage';

  $pop_query = "insert into temp_adgroup_ad(form_id,heading,ad_description,dest_url,personal_reference,garbage_val) values('".$_SESSION['form_id']."','".$_POST['txtHeadline'.$_SESSION['form_id']]."','".$_POST['text_description'.$_SESSION['form_id']]."','".$_POST['txtUrl'.$_SESSION['form_id']]."','".$_POST['txtAdName'.$_SESSION['form_id']]."','".$garbage."') " ;

 $res = mysql_query($pop_query);

$inner_res = mysql_query("select * from temp_adgroup_ad where form_id = '".$_SESSION['form_id']."'");
$startTable = '<table width="100%" style="color:#000000" cellpaddin="0" cellspacing="0" border="1" bgColor="#666666">';
$endTable = '</table>';
$i = 1;
while($inner_row = mysql_fetch_array($inner_res))
{
	$rowStr .= '<tr><td>'.$i.'</td><td>'.$inner_row['personal_reference'].'</td><td>'.$inner_row['heading'].'</td></tr>';
	$i++;
}
$finalResult = $startTable.$rowStr.$endTable;
?>

<script>
parent.window.opener.document.getElementById('tdCreateAd'+<?=$_SESSION['form_id']?>).innerHTML = '<?php echo $finalResult;?>' ;
self.close();
</script>

<?php



 }



// to get the type of ad query
$get_type_id = $_SESSION['type_id'] ; //$_POST['typeid'];
$res_type_query = mysql_query("select adspaceType from adspace_details where adspaceId = '".$get_type_id."' ");
$row_type_query = mysql_fetch_array($res_type_query);

if(isset($_POST['post_checking'])){
$adtype_retrieve=$_POST['network_type'];
}
else
$adtype_retrieve=$row_type_query['adspaceType'];
// End to get the type of ad query

// For file upload coding

if ($_FILES["file"]["error"] > 0)
  {
 // echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  $file_name = $_FILES["file"]["name"];
  $extension = explode('.',$file_name);  
  move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_SESSION[siteuserId] .".".$extension[1]);
  }


// End of file upload query


?>
<script>




// function submit_browse_form()
// {
// frmAvertise.submit();
// }

function main_page()
{
self.close();
}

function showhidSelectBox(mode)
{
if(mode!='none')
{
	document.getElementById('txtUrl<?=$_SESSION['form_id']?>').value=document.getElementById('selExistingAd').value;

}
else
{
	document.getElementById('txtUrl<?=$_SESSION['form_id']?>').value='';
document.getElementById('txtUrl<?=$_SESSION['form_id']?>').readOnly=false;
}
	document.getElementById('tdExistingAd<?=$_SESSION['form_id']?>').style.display=mode;
}


function validation()
{

var txtHeadline = document.getElementById("txtHeadline<?=$_SESSION['form_id']?>").value;
var txtUrl = document.getElementById("txtUrl<?=$_SESSION['form_id']?>").value;


var text_description = document.getElementById("text_description<?=$_SESSION['form_id']?>").value; 

if(text_description != "")    {
        document.getElementById("validate_text_description<?=$_SESSION['form_id']?>").style.display="none";
    }


if(txtHeadline != "")    {
        document.getElementById("txtHeadline_validate<?=$_SESSION['form_id']?>").style.display="none";
    }

if(txtUrl != "")    {
        document.getElementById("txtUrl_validate<?=$_SESSION['form_id']?>").style.display="none";
    }


if(txtHeadline == "")    {
        document.getElementById("txtHeadline_validate<?=$_SESSION['form_id']?>").style.display="block";
        //document.getElementById("txtHeadline_validate").innerHTML="Please Enter Headline!";
        document.getElementById("txtHeadline<?=$_SESSION['form_id']?>").focus();
        return false;
    }


if(text_description == "")    {
        document.getElementById("validate_text_description<?=$_SESSION['form_id']?>").style.display="block";
        document.getElementById("validate_text_description<?=$_SESSION['form_id']?>").innerHTML="Please Enter Desc!";
        document.getElementById("text_description<?=$_SESSION['form_id']?>").focus();
        return false;
    }



if(txtUrl == "")    {
        document.getElementById("txtUrl_validate<?=$_SESSION['form_id']?>").style.display="block";
        //document.getElementById("txtUrl_validate").innerHTML="Please Enter Destination Url!";
        document.getElementById("txtUrl<?=$_SESSION['form_id']?>").focus();
        return false;
    }

         

   
return true;
}


function preview_heading()
{
document.getElementById("prev_heading<?=$_SESSION['form_id']?>").value = document.getElementById("txtHeadline<?=$_SESSION['form_id']?>").value;
document.getElementById("prev_heading<?=$_SESSION['form_id']?>").innerHTML= document.getElementById("txtHeadline<?=$_SESSION['form_id']?>").value;
document.getElementById("prev_heading<?=$_SESSION['form_id']?>").style.display = 'block';
}

function preview_text_description_func()
{
document.getElementById("preview_text_description<?=$_SESSION['form_id']?>").value = document.getElementById("text_description<?=$_SESSION['form_id']?>").value;
document.getElementById("preview_text_description<?=$_SESSION['form_id']?>").innerHTML= document.getElementById("text_description<?=$_SESSION['form_id']?>").value;
document.getElementById("preview_text_description<?=$_SESSION['form_id']?>").style.display = 'block';
}

</script>
<input type="hidden" name="hidAdSpaceId" id="hidAdSpaceId" value="<?php echo $adspaceID;?>">
<input type="hidden" name="hidDelAdSpaceId" id="hidDelAdSpaceId" value="<?php echo $fetFavId[0];?>">


<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td align="center"><table class="advertise_area" cellpadding="0" cellspacing="0" width="827">
  <tbody><tr>
    <td class="advertise_txt" align="left" valign="top">
    <p>The world best 2 in 1</p>
    <p class="advertise_txt2">advertising network</p>
    </td>
  </tr>
</tbody></table></td>
  </tr>
  <tr>
    <td align="center"><table width="827" class="center" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="images/red_table_ltop.jpg" alt="" /></td>
    <td class="red_table_top"></td>
    <td><img src="images/red_table_rtop.jpg" alt="" /></td>
  </tr>
  <tr>
    <td class="red_table_LSide"></td>
    <!-- ban body part -->


    <td class="inner_contentArea" align="center">

	<table cellspacing="0" cellpadding="0" border="0">

		<tr>
			<TD> <!--Left TD-->
				<table>
			
					

        <TR>
          <TD align="left">&nbsp;</TD>
        </TR>
		
        <TR>
          <TD align="left">
		<table style="border:#CCCCCC 1px solid;" cellspacing="0" cellpadding="0">
                    
		<tr>
			<td> <!--LEFT TD-->
				<table>
			

			<form name="frmAvertise<?=$_SESSION['form_id']?>" id="frmAvertise<?=$_SESSION['form_id']?>" method="POST" enctype="multipart/form-data" action="">

			<input type="hidden" name="hidden_field<?=$_SESSION['form_id']?>" id="hidden_field<?=$_SESSION['form_id']?>" value="www">
			<input type="hidden" name="enddate" value="<?php echo $_REQUEST[duration];?>">
                    	<input type="hidden" name="adspaceid" value="<?php echo $_REQUEST[id];?>">
			 
		<tr>
                      <td valign="top" align="left">
			<table cellpadding="5" cellspacing="0" border="0">

			<tr>
                        	<td width="300" class="sitename" colspan="2">Create Your Ad</td>
                        </tr>
                          <TR>
				<TD align="right"><input checked="true" onclick="showhidSelectBox('none')" type="radio" name="radSelectAd" id="radSelectAd1"></TD>
				<td align="left"><strong>Use An existing page</strong></td>
			</tr>
			
			<TR>
				<TD align="right"><input onclick="showhidSelectBox('')"  type="radio" name="radSelectAd" id="radSelectAd2"></TD>
				<td align="left"><strong>Use a landing page</strong></td>
			</tr>
			<?php
			 $query_landing_page="select * from adspace_landing_page where UserId='".$_SESSION['siteuserId']."' ";
			$sql_landing_page=mysql_query($query_landing_page);
			$num_landing_page=mysql_num_rows($sql_landing_page);
			if($num_landing_page>0)
			{
 			?>
			<tr>
				<TD colspan="2" id="tdExistingAd" style="display:none;">&nbsp;
					<select name="selExistingAd" id="selExistingAd">
					<?php
						  while($res_landing_page= mysql_fetch_array($sql_landing_page)){
                                    ?>main_page
                                      <option value="<?=$GLOBALS['site_url'].$res_landing_page['pageName'].".php";?>"> <?=stripslashes($res_landing_page['pageName']);?></option>
                                    <?
                                        }
                                        ?>
					</select>
	<!--left td-->			</TD>
			</tr>
			<?php
			}
			else
			{
			?>	
				<TD colspan="2" id="tdExistingAd" style="display:none;">&nbsp;
                                    You do not have any Landing Pages. <a href="create_landing_page.php" class="register_link">Create a new Landing Page</a>
                                    </td>

			<?php
			}
			?>

			<tr><TD colspan="2">&nbsp;*Headline:</TD></tr>
			<tr><TD colspan="2">&nbsp;<input type="text" name="txtHeadline<?=$_SESSION['form_id']?>" id="txtHeadline<?=$_SESSION['form_id']?>" onkeyup="return preview_heading();"></TD>
			<TD colspan="2" id="txtHeadline_validate<?=$_SESSION['form_id']?>" style="display:none;">Please Enter Url!</TD>
			</tr>



			<tr><TD colspan="2">&nbsp;*Add Description</TD></tr>
			<tr><TD colspan="2">&nbsp;<textareA name="text_description<?=$_SESSION['form_id']?>" id="text_description<?=$_SESSION['form_id']?>" onkeyup="return preview_text_description_func();"></textareA></TD>
			<TD colspan="2" id="validate_text_description<?=$_SESSION['form_id']?>" style="display:none;">Please Enter Description !</TD>

</tr>


			<tr><TD colspan="2">&nbsp;*Destination URL (http://):</TD></tr>
			<tr><TD colspan="2">&nbsp;<input type="text" name="txtUrl<?=$_SESSION['form_id']?>" id="txtUrl<?=$_SESSION['form_id']?>"></TD>

			<TD colspan="2" id="txtUrl_validate<?=$_SESSION['form_id']?>" style="display:none;">Please Enter Destiny url!</TD></tr>

			<tr><TD colspan="2">&nbsp;Ad Name (For personal reference)</TD></tr>
			<tr><TD colspan="2">&nbsp;<input type="text" name="txtAdName<?=$_SESSION['form_id']?>" id="txtAdName<?=$_SESSION['form_id']?>"></TD></tr>
			<tr><TD colspan="2">&nbsp;</TD></tr>
			<tr><TD colspan="2">&nbsp;<input type="button" value="Cancel" onclick="return main_page();">&nbsp;<input type="submit" value="Save" name="addtocart<?=$_SESSION['form_id']?>" onclick="return validation();"></TD></tr>
			<tr><TD colspan="2">&nbsp;</TD></tr>

		</table>
	</td>
	<td width="50px" valign="top"></td> <!--Middle TD-->
 	<td valign="top"> <!--Right TD START-->


		<table>
			<tr valign="top">
                        	<td class="sitename" valign="top" align="center">Preview</td>
                        </tr>

			<tr>
                        	<td align="center" id="prev_heading<?=$_SESSION['form_id']?>"></td>
                        </tr>

			<tr>
                        	<td align="center" id="preview_text_description<?=$_SESSION['form_id']?>"></td>
                        </tr>


			<tr>
                        	<td>Please note: The Preview will not display correctly if you do not set the "Text size" to "Normal" on your browser.</td>
                        </tr>
		</table>
	</td> <!--Right TD END-->
		</tr>

                </table>
	</td>
                      
                      
                    </tr>
			</form>
                  </table>

		</TD>
				</table>
			</TD> 

	</tr>
       
        
       </table>
   </td>

    <!-- /ban body part -->
    <td class="red_table_RSide"></td>
  </tr>
  <tr>
    <td><img src="images/red_table_lbottom.jpg" alt="" /></td>
    <td class="red_table_bottom"></td>
    <td><img src="images/red_table_rbottom.jpg" alt="" /></td>
  </tr>
</table></td>
  </tr>
</table>
